package it.aekidna.cleverplatypus.gui.containers
{
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.system.Capabilities;
	
	import mx.core.UIComponent;

	public class ScreenMousePosition
	{
		private static var _position : Point = new Point();
		private static var _hotSpots : Object = {};
		
		private static var _stagePosition : Point = new Point();
		
		
		public static function registerHotSpot( 
			inName : String,
			inComponent : UIComponent, 
			inX : int, 
			inY : int ) : void
		{
			_hotSpots[ inName ] = new HotSpotInfo( inComponent, inX, inY );
		}
		
		public static function get mousePosition() : Point
		{
			return new Point( _position.x, _position.y );
		}
		
		public static function get stageMousePosition() : Point
		{
			return new Point( _stagePosition.x, _stagePosition.y );
		}
		
		public static function getHotSpot( inName : String ) : Point
		{
			var info : HotSpotInfo = HotSpotInfo( _hotSpots[ inName ] );
			if( info == null ) 
			{
				return new Point( 0, 0 );
			}
			return info.component.localToGlobal( new Point( info.x, info.y ) );
		}
		
		
	}
}
	import mx.core.UIComponent;
	import flash.utils.Dictionary;
	

class HotSpotInfo
{
	private var _weakDict : Dictionary = new Dictionary( true );
	
	public function HotSpotInfo( inComponent : UIComponent, inX : int, inY : int )
	{
		component = inComponent;
		x = inX;
		y = inY;
	}
	public function get component() : UIComponent
	{
		for each( var comp : UIComponent in _weakDict )
		{
			return comp;
		}
		return null;
	}
	
	public function set component( inComponent : UIComponent ) : void
	{
		_weakDict[ inComponent ] = inComponent;
	}
	
	public var x : int;
	public var y : int;
}